package logic

import (
	"context"
	"home-manage/homerpc/homerpc"

	"home-manage/api/internal/svc"
	"home-manage/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PasswordLogic {
	return &PasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PasswordLogic) Password(req *types.PasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	password, err := l.svcCtx.HomeRpc.Password(l.ctx, &homerpc.PasswordRequest{
		Tel:         req.Tel,
		SendSms:     req.SendSms,
		Password:    req.Password,
		Newpassword: req.Password,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}
	return &types.Response{
		Message: "密码修改成功",
		Data:    password,
		Code:    200,
	}, nil
}
